<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" th:href="@{/res/css/amazeui.min.css}"/>
    <link rel="stylesheet" th:href="@{/res/css/admin.css}"/>
    <script type="text/javascript" th:src="@{/js/jquery-1.11.3.min.js}"></script>
    <script type="text/javascript" th:src="@{/myplugs/js/plugs.js}"></script>

    <script type="text/javascript">

    </script>
</head>

<body>
<div class="admin-content-body">
    <div class="am-cf am-padding am-padding-bottom-0">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">交易记录</strong>
            <small></small>
        </div>
    </div>

    <hr>

    <div class="am-g">
        <div class="am-u-sm-12 am-u-md-6">
            <div class="am-btn-toolbar">
                <div class="am-btn-group am-btn-group-xs">
                    <button type="button" class="am-btn am-btn-default" onclick="cashout()"> 提现</button>
                </div>
            </div>
        </div>

    </div>

    <div class="am-g">
        <div class="am-u-sm-12">
            <form class="am-form">
                <table class="am-table am-table-striped am-table-hover table-main">
                    <thead>
                    <tr>
                        <th class="table-id">ID</th>
                        <th class="table-type">业务类型</th>
                        <th class="table-type">交易金额</th>
                        <th class="table-type">申请时间</th>
                        <th class="table-type">审核状态</th>
                    </tr>
                    </thead>

                    <tbody id="mytable"></tbody>
                </table>

                <div class="am-cf">
                    共<a><span id="listcount"></span></a>条记录
                    <!--<div class="am-fr">
                        <ul class="am-pagination">
                            <li class="am-disabled">
                                <a href="#">«</a>
                            </li>
                            <li class="am-active">
                                <a href="#">1</a>
                            </li>
                            <li>
                                <a href="#">2</a>
                            </li>
                            <li>
                                <a href="#">3</a>
                            </li>
                            <li>
                                <a href="#">»</a>
                            </li>
                        </ul>
                    </div>-->
                </div>
                <hr>
            </form>
        </div>
    </div>
</div>
</body>

<script>
    //uid从url得到
    var result = new Object();
    result = getParameter();
    var uid = result["uid"];

    //查找符合条件的记录
    function search() {
        //表格
        var $tbody = $("#mytable");

        //获取搜索条件
        var uName = document.getElementById("search").value;

        $.ajax({
            type: 'post',
            url: '/finance/selectByName',
            data: {name: uName},
            dataType: 'json',
            success: function (mydata) {
                console.log("Test");
                console.log(mydata);
                var newHtml = '';
                $("#listcount").html(" " + mydata.length / 2 + " ");
                for (i = 0; i < mydata.length; i = i + 2) {
                    newHtml += '<tr class="low-' + i + '">';
                    newHtml += '  <td>' + mydata[i].id + '</td>';
                    newHtml += '  <td>' + mydata[i + 1].name + '</td>';
                    newHtml += '  <td>' + mydata[i].type + '</td>';
                    newHtml += '  <td>' + mydata[i].money + '</td>';
                    newHtml += '  <td>' + timeFormat(mydata[i].applyTime) + '</td>';
                    newHtml += '  <td>' + mydata[i].state + '</td>';
                    newHtml += '</tr>';
                }
                $tbody.html(newHtml);
            },
            error: function () {
                alert("error");
            }
        })
    }

    //提现
    function cashout() {
        $.jq_Panel({
            title: "提现操作",
            iframeWidth: 450,
            iframeHeight: 200,
            url: "/walletCashout?uid=" + uid
        });
    }



    $(function () {
        //表格
        var $tbody = $("#mytable");

        $.ajax({
            type: 'post',
            url: '/wallet/selectListByUid',
            data: {uid: uid},
            dataType: 'json',
            success: function (mydata) {
                var newHtml = '';
                $("#listcount").html(" " + mydata.length + " ");
                for (i = 0; i < mydata.length; i++) {
                    newHtml += '<tr class="low-' + i + '">';
                    newHtml += '  <td>' + mydata[i].id + '</td>';
                    newHtml += '  <td>' + mydata[i].type + '</td>';
                    newHtml += '  <td>' + mydata[i].money + '</td>';
                    newHtml += '  <td>' + timeFormat(mydata[i].applyTime) + '</td>';
                    newHtml += '  <td>' + mydata[i].state + '</td>';
                    newHtml += '</tr>';
                }
                $tbody.html(newHtml);
            },
            error: function () {
                alert("error");
            }
        })
    });



    //json时间格式转换
    function timeFormat(time) {
        var d = new Date(time);

        var year = d.getFullYear();       //年
        var month = d.getMonth() + 1;     //月
        var day = d.getDate();            //日

        var hh = d.getHours();            //时
        var mm = d.getMinutes();          //分
        var ss = d.getSeconds();           //秒

        var clock = year + "/";

        if (month < 10)
            clock += "0";

        clock += month + "/";

        if (day < 10)
            clock += "0";

        clock += day + " ";

        if (hh < 10)
            clock += "0";

        clock += hh + ":";
        if (mm < 10) clock += '0';
        clock += mm + ":";

        if (ss < 10) clock += '0';
        clock += ss;
        return (clock);
    };



    //解析url传值
    function getParameter() {
        var url = location.search;//获取url?后面的内容
        var result = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                result[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
            }
        }
        return result;
    }

</script>
</html>